/**
* 作者: liubaoyuan
* 日期: 2024-10-25 17:22:17
* 备注: 玩家约会秘书信息表
*/
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserDatingSecretary;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserDatingSecretaryModel extends BaseModel implements Model {
	public static final String LISTKEY = "user_id.secretary_id";
	public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
	public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
	public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

	protected long id; // 数据库id
	protected long userId; // 玩家id
	protected int secretaryId; // 秘书id
	protected int datingCount; // 密会踏青次数
	protected long lastDatingTime; // 上次踏青时间

	public void reset() {
	}

	protected String getKey() {
		return "UserDatingSecretary." + userId + "." + secretaryId;
	}

	protected String getListKey() {
		return "UserDatingSecretary." + userId;
	}

	protected String getListItemKey() {
		return secretaryId + "";
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public void setTableId() {
		putId(incrTableId("user_dating_secretary"));
	}

	public JsonObject insert() {
		return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	public void delete() {
		super.delete(getKey(), id, UPDATE_DB_TYPE, userId, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	/**
	* 根据入库类型更新
	*/
	public JsonObject update() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, userId, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	* 实时入队列
	*/
	public JsonObject updateQueueNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	public JsonObject getAllObj(){
		JsonObject obj = new JsonObject();
		obj.put("id", id); // 数据库id
		obj.put("userId", userId); // 玩家id
		obj.put("secretaryId", secretaryId); // 秘书id
		obj.put("datingCount", datingCount); // 密会踏青次数
		obj.put("lastDatingTime", lastDatingTime); // 上次踏青时间
		return obj;
	}

	public PBUserDatingSecretary.Builder takeInitBuilder() {
		PBUserDatingSecretary.Builder sb = PBUserDatingSecretary.newBuilder();
		if (secretaryId != 0) {
			sb.setSecretaryId(secretaryId);
		}
		if (datingCount != 0) {
			sb.setDatingCount(datingCount);
		}
		return sb;
	}

	public PBUserDatingSecretary.Builder takeBuilder() {
		if (updateObj == null || updateObj.isEmpty()) {
			return takeInitBuilder();
		}
		PBUserDatingSecretary.Builder sb = PBUserDatingSecretary.newBuilder();
		if (isFieldUpdate("secretaryId")) {
			sb.setSecretaryId(secretaryId);
		}
		if (isFieldUpdate("datingCount")) {
			sb.setDatingCount(datingCount);
		}
		return sb;
	}

	public long getId() {
		return id;
	}

	public void putId(long id) {
		if (this.id != id) {
			this.id = id;
			updateRedisHashField(getKey(), "id", this.id);
		}
	}

	public void addId(long value) {
		this.id += value;
		updateRedisHashField(getKey(), "id", this.id);
	}

	public long getUserId() {
		return userId;
	}

	public void putUserId(long userId) {
		if (this.userId != userId) {
			this.userId = userId;
			updateRedisHashField(getKey(), "userId", this.userId);
		}
	}

	public void addUserId(long value) {
		this.userId += value;
		updateRedisHashField(getKey(), "userId", this.userId);
	}

	public int getSecretaryId() {
		return secretaryId;
	}

	public void putSecretaryId(int secretaryId) {
		if (this.secretaryId != secretaryId) {
			this.secretaryId = secretaryId;
			updateRedisHashField(getKey(), "secretaryId", this.secretaryId);
		}
	}

	public void addSecretaryId(int value) {
		this.secretaryId += value;
		updateRedisHashField(getKey(), "secretaryId", this.secretaryId);
	}

	public int getDatingCount() {
		return datingCount;
	}

	public void putDatingCount(int datingCount) {
		if (this.datingCount != datingCount) {
			this.datingCount = datingCount;
			updateRedisHashField(getKey(), "datingCount", this.datingCount);
		}
	}

	public void addDatingCount(int value) {
		this.datingCount += value;
		updateRedisHashField(getKey(), "datingCount", this.datingCount);
	}

	public long getLastDatingTime() {
		return lastDatingTime;
	}

	public void putLastDatingTime(long lastDatingTime) {
		if (this.lastDatingTime != lastDatingTime) {
			this.lastDatingTime = lastDatingTime;
			updateRedisHashField(getKey(), "lastDatingTime", this.lastDatingTime);
		}
	}

	public void addLastDatingTime(long value) {
		this.lastDatingTime += value;
		updateRedisHashField(getKey(), "lastDatingTime", this.lastDatingTime);
	}

}